package com.ruoyi.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PmsPurchaseRequisitions;
import com.ruoyi.system.service.IPmsPurchaseRequisitionsService;
import com.ruoyi.system.service.IWmsInboundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 采购申请单主Controller
 *
 * @author ruoyi
 * @date 2025-07-08
 */
@RestController
@RequestMapping("/system/pmsPurchaseRequisitions")
public class PmsPurchaseRequisitionsController extends BaseController
{
    @Autowired
    private IPmsPurchaseRequisitionsService pmsPurchaseRequisitionsService;
    @Autowired
    private IWmsInboundService wmsInboundService;

    /**
     * 查询采购申请单主列表
     */
    @SaCheckPermission("system:pmsPurchaseRequisitions:list")
    @GetMapping("/list")
    public TableDataInfo<PmsPurchaseRequisitions> list(PmsPurchaseRequisitions pmsPurchaseRequisitions, PageQuery pageQuery)
    {
        return pmsPurchaseRequisitionsService.selectPmsPurchaseRequisitionsList(pmsPurchaseRequisitions,pageQuery);
    }

    /**
     * 导出采购申请单主列表
     */
    /*@SaCheckPermission("system:pmsPurchaseRequisitions:export")
    @Log(title = "采购申请单主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmsPurchaseRequisitions pmsPurchaseRequisitions)
    {
        List<PmsPurchaseRequisitions> list = pmsPurchaseRequisitionsService.selectPmsPurchaseRequisitionsList(pmsPurchaseRequisitions);
        ExcelUtil<PmsPurchaseRequisitions> util = new ExcelUtil<PmsPurchaseRequisitions>(PmsPurchaseRequisitions.class);
        util.exportExcel(response, list, "采购申请单主数据");
    }*/

    /**
     * 获取采购申请单主详细信息
     */
    @SaCheckPermission("system:pmsPurchaseRequisitions:query")
    @GetMapping(value = "/{prId}")
    public R<PmsPurchaseRequisitions> getInfo(@PathVariable("prId") Long prId)
    {
        return R.ok(pmsPurchaseRequisitionsService.selectPmsPurchaseRequisitionsByPrId(prId));
    }

    /**
     * 新增采购申请单主
     */
    @SaCheckPermission("system:pmsPurchaseRequisitions:add")
    @Log(title = "采购申请单主", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@RequestBody PmsPurchaseRequisitions pmsPurchaseRequisitions)
    {
        return toAjax(pmsPurchaseRequisitionsService.insertPmsPurchaseRequisitions(pmsPurchaseRequisitions));
    }

    /**
     * 修改采购申请单主
     */
    @SaCheckPermission("system:pmsPurchaseRequisitions:edit")
    @Log(title = "采购申请单主", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@RequestBody PmsPurchaseRequisitions pmsPurchaseRequisitions)
    {
        return toAjax(pmsPurchaseRequisitionsService.updatePmsPurchaseRequisitions(pmsPurchaseRequisitions));
    }

    /**
     * 删除采购申请单主
     */
    @SaCheckPermission("system:pmsPurchaseRequisitions:remove")
    @Log(title = "采购申请单主", businessType = BusinessType.DELETE)
	@DeleteMapping("/{prIds}")
    public R<Void> remove(@PathVariable Long[] prIds)
    {
        return toAjax(pmsPurchaseRequisitionsService.deletePmsPurchaseRequisitionsByPrIds(prIds));
    }


    @SaCheckPermission("system:pmsPurchaseRequisitions:list")
    @GetMapping("/getPurchaseRequisitionsData")
    public R<PmsPurchaseRequisitions> getPurchaseRequisitionsData(){
        return R.ok(pmsPurchaseRequisitionsService.getPurchaseRequisitionsData());
    }

    /**
     * 取消入库单号
     */
    @SaCheckPermission("system:pmsPurchaseRequisitions:query")
    @GetMapping(value = "/clearOrderNo")
    public R<Void> clearOrderNo()
    {
        wmsInboundService.clearOrderNo();
        return R.ok();
    }
}
